package web.suzy.oj.controller.file;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.exception.StatusForbiddenException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.service.file.TestCaseService;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * YangSuzy 软件工作室
 * 类名: TestCaseController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/12/4 16:24
 */
@Controller
@RequestMapping("/api/file")
public class TestCaseController {
    @Autowired
    private TestCaseService testCaseService;

    /**
     * 方法名: uploadTestcaseZip
     * 描述: 上传测试用例zip压缩文件
     *
     * @param file zip压缩文件
     * @param mode 评测模式
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/12/4 16:25
     * @auther YangSuzy
     **/
    @PostMapping("/upload-testcase-zip")
    @ResponseBody
    @RequiresAuthentication
    public ResultBean<Map<Object, Object>> uploadTestcaseZip(
            @RequestParam("file") MultipartFile file,
            @RequestParam(value = "mode", defaultValue = "default") String mode) {
        return testCaseService.uploadTestcaseZip(file, mode);
    }

    /**
     * 方法名: downloadTestcase
     * 描述: 根据题号下载测试用例
     *
     * @param pid      题目ID
     * @param response 响应
     * @return void
     * @date 2022/12/4 16:35
     * @auther YangSuzy
     **/
    @GetMapping("/download-testcase")
    @RequiresAuthentication
    public void downloadTestcase(@RequestParam("pid") Long pid, HttpServletResponse response) throws StatusFailException, StatusForbiddenException {
        testCaseService.downloadTestcase(pid, response);
    }
}
